<template>
	<view>
		<!-- 懒加载动画 -->
		<view class="loading-box">
		  <u-loading :show="loadingone" color="#41ADBA" size="70"></u-loading>
		</view>
		<view v-show="isLoadingOver">
			<navbar name="我的设备"></navbar>
			<view  hover-class="actaveborder" class="facility-view" v-for="(item,idx) in equipmentList" :key="idx" @tap="navpages(item,idx,'equipment')">
				<view class="facility-image">
					<u-lazy-load border-radius="10" height="100" img-mode="aspectFill"
					  :image="item.equipmentIcon"></u-lazy-load>
				</view>
				<view class="facility-body">
					<view class="facility-title">
						{{item.equipmentName}}
					</view>
						{{item.remark}}
				</view>
			</view>
			<view class="equipment-none" v-show="noEquipment">
				<image class="equipmentImage" src="https://bsyjk-pic.bsyjk.cn/shapeicon/6BA822709EF840F6B2353F3029759A39.png"
					mode="设备"></image>
				暂无设备
			</view>
			<button @click="nav('add')" class="addFacility" type="default">添加新设备</button>
		</view>
	</view>

</template>

<script>
	import uLoading from "@/uview-ui/components/u-loading/u-loading.vue"

import uLazyLoad from "@/uview-ui/components/u-lazy-load/u-lazy-load.vue"


	export default {
		components: {
			uLoading,
			uLazyLoad,
		},
		data() {
			return {
				loadingone:false,
				equipmentList: [],
				isLoadingOver:false,//是否已将请求完接口了
				noEquipment:false,//没有设备
			}
		},

		onLoad(options) {
		},
		onShow() {
			this.tbEquipmentUser()
		},
		methods: {
			navpages(item,idx,type){
				console.log(item,idx,type)
				uni.navigateTo({
					url:'/pages/subpackage/home/healthData/healthData'
				})
			},
			tbEquipmentUser() {
				this.loadingone = true;
				let _this = this;
				// uni.getStorageSync(global.IS_DEV?'USER_DATA_BSY_T':'USER_DATA_BSY_Z').userId
				this.$api.get(global.apiUrls.tbEquipmentUser + '?userId=' + uni.getStorageSync(global.IS_DEV?'USER_DATA_BSY_T':'USER_DATA_BSY_Z').userId, {})
					.then(res => {
						if(res.data.code == 1000){
							let result = res.data.result.records;
							_this.equipmentList = result
							this.isLoadingOver = true;
							if(res.data.result.total == 0){
								_this.noEquipment = true;
							}else{
								_this.noEquipment = false;
							}
							_this.loadingone = false;
							this.isLoadingOver = true;
						}else{
							_this.loadingone = false;
							this.isLoadingOver = true;
							_this.noEquipment = false;
						}

					}).catch(err => {})
			},
			nav(page) {
			// 测试
				wx.openBluetoothAdapter({ //调用微信小程序api 打开蓝牙适配器接口
					success: function(res) {
						uni.navigateTo({
							url: '/pagesMy/my/equipment/newequipment'
						})
					},
					fail: function(res) { //如果手机上的蓝牙没有打开，可以提醒用户
						wx.showToast({
							title: '请开启蓝牙',
							icon: 'none',
							duration: 1000
						})
					}
				})

			}
		}
	}
</script>

<style lang="scss">
	.equipment-none {
		font-size: 30upx;
		font-weight: 500;
		color: #9B9B9B;
		line-height: 42upx;
		text-align: center;

		.equipmentImage {
			width: 148upx;
			height: 148upx;
			display: block;
			margin: 400upx auto 11upx;
		}
	}

	.addFacility {
		width: 655upx;
		height: 90upx;
		background: url(https://bsyjk-pic.bsyjk.cn/toprbg/10099E8526734AC383D6ADEED897F016.png)no-repeat;
		background-size: 655upx 507upx;
		// background: linear-gradient(112deg, #81C042 0%, #2EA7E0 100%);
		border-radius: 45upx;
		font-size: 34upx;
		font-weight: 400;
		color: #FFFFFF !important;
		position: fixed;
		bottom: 30upx;
		left: 50%;
		transform: translateX(-50%);
	}
	.facility-view{
		width: 702upx;
		height: 134upx;
		background: #fff;
		margin: 30upx auto 0;
		border-radius: 16upx;
		display: flex;
		padding: 20upx 17upx;
		.facility-image{
			width: 100upx;
			height: 100upx;
			margin-right: 20upx;
		}
		.facility-body{
			font-size: 24upx;
			font-weight: 400;
			color: #9B9B9B;
			line-height: 33upx;
			.facility-title{
				font-size: 30upx;
				font-weight: 500;
				color: #2EA7E0;
				line-height: 48upx
			}
		}
	}
</style>
